package com.miyu.system.controller.open;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.miyu.system.service.open.SysOpenApiService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统开放api控制器
 * @author MIYU
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("sysOpenApi")
public class SysOpenApiController {

    private final SysOpenApiService openApiService;
    /**
     * 查询系统城市
     * @return {@link JSONArray}
     */
    @RequestMapping("getSysCity")
    public JSONArray getSysCity(){
        return openApiService.getSysCity();
    }

    /**
     * 获取天气
     * @param param 参数
     * @return {@link JSONObject}
     * @throws Exception 异常
     */
    @RequestMapping("weather")
    public JSONObject getWeather(@RequestBody JSONObject param) throws Exception {
        String vCity = "";
        if(!param.containsKey("version")){
            param.put("version","v1");
            vCity+="v1";
        }else {
            vCity+=param.getString("version");
        }
        if(!param.containsKey("city")){
            /*默认北京*/
            param.put("city","101010100");
            vCity+="101010100";
        }else {
            vCity+=param.getString("city");
        }
        param.put("vCity",vCity);
        return openApiService.getWeather(param);
    }
}
